/*
 * Year2000AlarmFixer.java
 *
 * Created on August 27, 2002, 1:44 PM
 *
 * Copyright (c) 2002 The General Electric Company
 */

package com.ge.healthcare.autosc.processor.magmon.y2k;

import com.ge.healthcare.autosc.common.ASCLogger;

/**
 * Fixes year-2000 compliance problems for ASCII files which are in
 *  magalarm.log format.  Two or three digit years are converted to
 *  four digit years by adding 1900 to their values.
 *
 * @author Daniel S. Horwitz, Compuware Corp.
 *
 * @version AutoSC P5P6
 */
public class Year2000AlarmFixer implements Year2000Fixer
{
    /**
     * Construct a year-2000 fixer for magalarm.log format files.
     */
    public Year2000AlarmFixer()
    {
        super();
    }

    /**
     * Get a year-2000 compliant version of the specified line of data.
     *
     * @param sourceLine The line of source data.
     *
     * @return A year-2000 compliant version of the source data.
     */
    public String getCompliant( String sourceLine )
    {
        final int dashIdx = sourceLine.indexOf( '-' );
        if ( (dashIdx != 2) && (dashIdx != 3) )
        {
            return sourceLine;
        }
        String yearString = sourceLine.substring( 0, dashIdx );
        String afterYearString = sourceLine.substring( dashIdx );
        int year = 0;
        try
        {
            year = Integer.parseInt( yearString, 10 );
        }
        catch ( NumberFormatException e )
        {
            year = 85;
        }
        year += 1900;
        ASCLogger.info(this.getClass(), "getCompliant", "Fix Y2K by convertfrom to " + year);
        return year + afterYearString;
    }
}
